package cn.com.simple.learning.rabbitmq.mq.producer;

import cn.com.simple.learning.rabbitmq.config.StreamDelayPipeline;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.time.LocalDateTime;

/**
 * @author Jianxing.Jia
 * @date 2022/5/25
 * @description 描述信息
 */
@Slf4j
@EnableBinding(StreamDelayPipeline.class)
public class MyProducer {

    private final MessageChannel messageChannel;

    public MyProducer(@Qualifier(StreamDelayPipeline.SEND) MessageChannel messageChannel) {
        this.messageChannel = messageChannel;
    }

    public void send(String msg) {
        log.info("开始送消息，{}，当前时间为，{}", msg,  LocalDateTime.now());
        Message<String> message = MessageBuilder.withPayload(msg).setHeader("x-delay",5000).build();
        messageChannel.send(message);
    }
}
